﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

// std headers
#include <memory>

// Qt headers
#include <QFrame>

// custom headers


class QLabel;
class QComboBox;
class QLayout;
class QStackedLayout;

namespace gmepgcs
{
    struct IDetailedProjectComponent;
    struct IParameter;
    class ParametersTableModel;
    class ImageSlider;
    struct ILegend;
    struct IPerformanceCurveDefinition;
    class HollowButtonTab;
    class TopLineTab;
    //class ProjectComponent3DViewPanel;
    struct ISpecification;
}

namespace gmepgcs
{
    class ProjectComponentDetailPanel : public QWidget
    {
        Q_OBJECT

    public:
        explicit ProjectComponentDetailPanel(QWidget *parent = nullptr);
        virtual ~ProjectComponentDetailPanel();

    public:
        void SetDetailedComponent(std::shared_ptr<IDetailedProjectComponent> spDetailedComponent);
        void SetBorder(int32_t left, int32_t top, int32_t right, int32_t bottom, QColor &color);
        void SetReplaceButtonVisiable(bool b);
        bool SetEditButtonVisiable(bool bVisible) const;
        std::wstring GetCurrentSpecification() const;
        void SetIsPrivateEnv(bool isPrivateEnv);
    signals:
        void OnProjectComponentEditingPageRequired();
        void OnProjectComponentEditingRequired(const std::wstring &projectId, const std::wstring &enterpriseId, const std::wstring &componentId, const int32_t &componentVersion, const std::wstring &componentName);
        void ReplaceWithPublicRequired(const std::wstring &projectId, const std::wstring &projectComponentId);

    public slots:
        void OnSelectedSpecificationChanged(const QString &spec);
        void ShowLegends(std::vector<std::shared_ptr<ILegend>> spLegends);
        void RefreshPerformanceCurveDefinitions(std::shared_ptr<std::vector<IPerformanceCurveDefinition *>> spCurveDefintions);
                
    protected:
        virtual void paintEvent(QPaintEvent *event) override;

    private:
        void InitUI();
        QLayout *InitMainPanel();
        QLayout *InitEmptyPanel();
        void RefreshData();
        void RefreshComponentName();
        void RefreshCategory();
        void RefreshThumbnails();
        //void SetComponentOf3DView();
        void RefreshSpecifications();
        void RefreshLegends();

    private slots:
        void OnCurrentTabChanged(QString currentTabHeader);
        void StartEdit();

    private:
        std::shared_ptr<IDetailedProjectComponent> m_spDetailedComponent;
        QLabel *m_pComponentNameLabel;
        QLabel *m_pCategoryLabel;
        QComboBox *m_pSpecComboBox;
        ParametersTableModel *m_pGeometricParameterTableModel;
        ParametersTableModel *m_pPropertyTableModel;
        ImageSlider *m_pComponentThumnailSlider;
        ImageSlider *m_pLegendThumnailSlider;
        QMargins m_border;
        QColor m_borderColor;
        QString m_currentSpecification;
        //ProjectPerformanceCurvesPanel *pPerformanceCurvePanel;
        TopLineTab *pParametersAndPerformanceCurvesTab;
        //ProjectComponent3DViewPanel *m_pProjectComponent3DViewPanel;
        HollowButtonTab *m_pThubmnailAndLegendTab;
        QPushButton *m_pBtnReplaceWithPublic;
    private:
        QLabel *m_pLblComponentNameInEmptyPanel;
        QLabel *m_pLblComponentCategoryInEmptyPanel;
        QLabel *m_pLblEmptyTipImage;
        QLabel *m_pLblEmptyTipIcon;
        QLabel *m_pLblEmptyTipText;

    private:
        QStackedLayout *m_pStackedLayout;

        bool m_isPrivateEnv = false;
    };
}